package com.software.notification.notification;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.software.notification.R;
import com.software.notification.utils.NotifyUtil;

public class NotificationActivity extends AppCompatActivity implements View.OnClickListener{

    private EditText edt_message;
    private Button btn_send;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification);
        initViews();
        initEvents();
    }

    private void initEvents() {
        btn_send.setOnClickListener(this);
    }

    private void initViews() {
        edt_message = findViewById(R.id.edt_message);
        btn_send = findViewById(R.id.btn_send);
    }

    @Override
    public void onClick(View v) {
//        //发送通知:
//        //获取通知管理器
//        NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
//
//        //创建渠道
//        NotificationChannel channel = new NotificationChannel(
//                "wechat",
//                "微信",
//                NotificationManager.IMPORTANCE_DEFAULT
//        );
//        manager.createNotificationChannel(channel);
//        //获取builder
//        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "wechat");
//        builder.setSmallIcon(R.mipmap.msg)
//                .setContentTitle("微信")
//                .setContentText(edt_message.getText())
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.msg));
//        //构建通知
//        Notification notification = builder.build();
//
//
//        //发送通知
//        manager.notify(R.string.app_name, notification);
        NotifyUtil notify = new NotifyUtil(this, NotificationManager.IMPORTANCE_DEFAULT);
        notify.sendNotify("微信", edt_message.getText().toString(), R.mipmap.msg, R.mipmap.msg);
    }
}